package com.siloam.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.siloam.dao.PrayerDao;
import com.siloam.module.Prayer;
import com.siloam.vo.PageVO;
import com.siloam.vo.PrayerVO;

public class PrayerService {

	private PrayerDao prayerDao;
	
	public PrayerDao getPrayerDao() {
		return prayerDao;
	}

	public void setPrayerDao(PrayerDao prayerDao) {
		this.prayerDao = prayerDao;
	}

	@Transactional
	public void add(Prayer prayer){
		prayerDao.add(prayer);
	}

	public PageVO<PrayerVO> findUserPrayer(int userId, int rowBeginIndex, int rowCount){
		PageVO<PrayerVO> pageVO = new PageVO<PrayerVO>();
		pageVO.setTotal(prayerDao.findCountByUser(userId));
		
		List<PrayerVO> prayerVOS = new ArrayList<PrayerVO>();
		List<Prayer> prayers = prayerDao.findPageByUser(userId, rowBeginIndex, rowCount);
		for(Prayer prayer : prayers){
			prayerVOS.add(new PrayerVO(prayer));
		}
		pageVO.setRows(prayerVOS);
		return pageVO;
	}
	
	@Transactional
	public void delete(int id){
		prayerDao.delete(id);
	}
	
	@Transactional
	public void setStatus(int id, int status){
		prayerDao.setStatus(id, status);
	}
	
}
